package com.alvin.mbp.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alvin.mbp.entity.PointMember;
import com.alvin.mbp.service.PointMemberService;

@Controller
public class RegisterAction {

    @Autowired
    private PointMemberService pointMemberService;

    @RequestMapping(value = "/register.htm", method = RequestMethod.POST)
    public String register(Model model, PointMember member, HttpServletRequest request) {
        String mobile = member.getMobile();
        member = pointMemberService.findByPropertyOne("mobile", member.getMobile());
        if (member != null) {
            request.getSession().setAttribute("MEMBER", member);
            return "redirect:/home.htm";
        } else {
            model.addAttribute("msg", "用户名或密码错误!");
            model.addAttribute("mobile", mobile);
        }
        return "redirect:/login.htm";

    }

    @RequestMapping(value = "/register.htm", method = RequestMethod.GET)
    public String register() {
        return "/register";

    }


}
